﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using GemCase.Model;

namespace GemCase.View
{
    /// <summary>
    /// Interaction logic for CutView.xaml
    /// </summary>
    public partial class EditView : Window
    {
        public EditView()
        {
            var x = new EditViewModel();
            InitializeComponent();
            this.DataContext = x;
        }

        private void Card_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            MainStackPanel.Height = Card.Height + 10;
        }

        private void MainCanvas_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
          
        }

        private void ItemImage_OnMouseMove(object sender, MouseEventArgs e)
        {
            var img = sender as Image;
           
            var itempoint = img?.TranslatePoint(new Point(0, 0), MainCanvas);

            DragImg.Height = 20;
            DragImg.Width = 20;

            Canvas.SetTop(DragImg, itempoint.Value.Y);
            Canvas.SetLeft(DragImg, itempoint.Value.X);
            DragImg.Visibility = Visibility.Visible;
        }

        private void BufferList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
           
        }

        private void DragImg_MouseLeave(object sender, MouseEventArgs e)
        {
            DragImg.Visibility = Visibility.Hidden;
        }

        private void BufferList_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var list = sender as ListBox;
            var item = BufferList.ItemContainerGenerator.ContainerFromIndex(list.SelectedIndex) as ListBoxItem;
            var point = item.TranslatePoint(new Point(0, 0), MainCanvas);

            DragImg.Height = 120;
            DragImg.Width = 120;
            Canvas.SetTop(DragImg, point.Y);
            Canvas.SetLeft(DragImg, point.X);
            DragImg.Visibility = Visibility.Visible;
        }
    }
}
